# -*- coding: utf-8 -*-
"""
@Project: base_python
@File: seleniumtest2.py
@Author: PC
@Date: 2025/06/19
@Description: 
"""
from selenium import webdriver
import time
from selenium.webdriver.remote.webelement import WebElement
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.by import By

def waitForLoad(driver):
    # elem = driver.find_element_by_tag_name("html")
    elem = driver.find_element(By.TAG_NAME, 'html')
    count = 0
    while True:
        count += 1
        if count > 20:
            print('Timing out after 10 seconds and returning')
            return
        time.sleep(.5)
        try:
            elem == driver.find_element(By.TAG_NAME, 'html')
        except StaleElementReferenceException:
            return

# driver = webdriver.PhantomJS(executable_path='<Path to Phantom JS>')
driver = webdriver.Chrome()
driver.get('http://pythonscraping.com/pages/javascript/redirectDemo1.html')
waitForLoad(driver)
print(driver.page_source)
